package com.itheima.d8_thread_pool;

import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/*
    目标：掌握线程池的创建。
    需求 : 使用线程池处理Runnable类型任务
 */
public class ThreadPoolTest2 {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(3,
                10,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(20),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
        for (int i = 1; i <= 31; i++){
            executor.submit(new Studenr("学生" + i));
        }

//        executor.shutdown();
//        List<Runnable> runnables = executor.shutdownNow();
//        System.out.println(runnables);


    }

}
class Studenr  implements Runnable{
    private String name;
    public Studenr(String name)
    {
        this.name = name;
    }

    public void run(){
        System.out.println(Thread.currentThread().getName()+"正在教"+ name+ "学游泳");
    }
}